<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv='refresh' content='60'>
	<title><?php echo $view_title?></title>
	<link rel=stylesheet href='./template/<?php echo $OJ_TEMPLATE?>/<?php echo isset($OJ_CSS)?$OJ_CSS:"hoj.css" ?>' type='text/css'>
</head>
<body>
<div id="wrapper">
	<?php require_once("contest-header.php");?>
<div id=main>

<?php 
if (isset($_GET['cid'])){
			$cid=intval($_GET['cid']);
			$view_cid=$cid;
}
?>
<div id=center>

<center><h3>Contest<?php echo $view_cid?> - 状态</h3></center>

<ul class="nav nav-pills contest-nav" id="fn-nav">
    <li ><a href="contest.php?cid=<?php echo $view_cid?>">题目</a></li>
    <li ><a href="contestrank.php?cid=<?php echo $view_cid?>">排名</a></li>
    <li ><a href="conteststatistics.php?cid=<?php echo $view_cid?>">统计</a></li>
    <li class="active" ><a href="status.php?cid=<?php echo $view_cid?>">状态</a></li>
    <!--li ><a href="/contest/talk?cid=1103">答疑</a></li-->
</ul>




<form action="status.php" method="GET" class="form-inline status-filter" role="form">
    <div class="form-group">
        <label class="sr-only" for="pid">题号</label>
        <input placeholder="题号" name="problem_id" id="pid" class="form-control"/>
		<input type='hidden' name='cid' value='<?php echo $view_cid;?>'>
    </div>&nbsp;
    <div class="form-group">
        <label class="sr-only" for="udi">用户</label>
        <input placeholder="用户" name="user_id" id="uid" class="form-control"/>
    </div>&nbsp;
    <div class="form-group">
        <label class="sr-only" for="language">语言</label>
        <select name="language" class="form-control">
            <option value="-1" selected="selected">全部语言</option>
                    <option value="0">C</option>
                    <option value="1">C++</option>
                    <option value="2">Pascal</option>
                    <option value="3">Java</option>
                </select>
    </div>&nbsp;
    <div class="form-group">
        <label class="sr-only" for="result">结果</label>
        <select name="jresult" class="form-control">
            <option value="-1" selected="selected">全部结果</option>
                    <option value="4">正确答案</option>
                    <option value="5">表达错误</option>
                    <option value="6">错误答案</option>
                    <option value="7">时间超限</option>
                    <option value="8">内存超限</option>
                    <option value="9">输出超限</option>
                    <option value="10">运行错误</option>
                    <option value="11">编译错误</option>
                    <option value="12">编译成功</option>
                    <option value="13">测试运行</option>
                    <option value="0">等待评测</option>
                    <option value="1">等待重测</option>
                    <option value="2">正在编译</option>
                    <option value="3">正在运行</option>
                </select>
    </div>&nbsp;
    <input type="submit" value="筛选" class="btn btn-default">
</form>




<div>
<table class="table table-striped table-condensed table-bordered" width=100%>
<thead>
<tr  class='toprow'>
<th ><?php echo $MSG_RUNID?>
<th ><?php echo $MSG_USER?>
<th ><?php echo $MSG_PROBLEM?>
<th ><?php echo $MSG_RESULT?>
<th ><?php echo $MSG_MEMORY?>
<th ><?php echo $MSG_TIME?>
<th ><?php echo $MSG_LANG?>
<th ><?php echo $MSG_CODE_LENGTH?>
<th ><?php echo $MSG_SUBMIT_TIME?>
</tr>
</thead>

<tbody>
			<?php 
			$cnt=0;
			foreach($view_status as $row){
				echo "<tr>";
				foreach($row as $table_cell){
					echo "<td>";
					echo "\t".$table_cell;
					echo "</td>";
				}
				
				echo "</tr>";
				
				$cnt=1-$cnt;
			}
			?>
			</tbody>
</table>

</div>

<ul class="pager rank-pager">
    <li><a href=<?php echo getenv("HTTP_REFERER");?>> 上一页 </a></li>
    <li><a href="status.php?<?php echo $str2;?>&top=<?php echo $bottom;?>&prevtop=<?php echo $top;?>"> 下一页 </a></li>
</ul>




<div id=foot>
	<?php require_once("oj-footer.php");?>

</div><!--end foot-->
</div><!--end main-->
</div><!--end wrapper-->
<script type="text/javascript">
  var i=0;
  var judge_result=[<?php
  foreach($judge_result as $result){
    echo "'$result',";
  }
?>''];
//alert(judge_result[0]);
function findRow(solution_id){
    var tb=window.document.getElementById('result-tab');
     var rows=tb.rows;

      for(var i=1;i<rows.length;i++){
                var cell=rows[i].cells[0];
//              alert(cell.innerHTML+solution_id);
        if(cell.innerHTML==solution_id) return rows[i];
      }
}

function fresh_result(solution_id)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     var tb=window.document.getElementById('result-tab');
     var row=findRow(solution_id);
     //alert(row);
     var r=xmlhttp.responseText;
     var ra=r.split(",");
//     alert(r);
//     alert(judge_result[r]);
      var loader="<img width=18 src=image/loader.gif>";
      row.cells[3].innerHTML="<span class='btn btn-warning'>"+judge_result[ra[0]]+"</span>"+loader;

     row.cells[4].innerHTML=ra[1];
     row.cells[5].innerHTML=ra[2];
     if(ra[0]<4)
        window.setTimeout("fresh_result("+solution_id+")",2000);
     else
        window.location.reload();

    }
  }
xmlhttp.open("GET","status-ajax.php?solution_id="+solution_id,true);
xmlhttp.send();
}
<?php if ($last>0&&$_SESSION['user_id']==$_GET['user_id']) echo "fresh_result($last);";?>
</script>

</body>
</html>
